package org.ichow.utils
{
	
	/**
	 * ...
	 * Randomly Shuffle Array
	 * @author Minos
	 */
	public class ShuffleUtil
	{
		/**
		 * shuffle array by splice
		 * @param	array
		 * @param	length		
		 * @return
		 */
		public static function splicing( array : Array , length : int ) : Array
		{
			var shuffled : Array = new Array( length );
			var randomPos : Number = 0;
			for ( var i : int = 0 ; i < length ; i++ )
			{
				randomPos = int( Math.random() * array.length );
				shuffled[ i ] = array.splice( randomPos , 1 )[ 0 ];
			}
			return shuffled;
		}
		
		/**
		 * shuffle array by sort
		 * @param	array
		 * @return
		 */
		public static function sorting( array : Array ) : Array
		{
			function randomSort( a : * , b : * ) : Number
			{
				if ( Math.random() < 0.5 )
					return -1;
				else
					return 1;
			}
			return array.sort( randomSort );
		}
	
	}

}